<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #contact{
            width: 200px;
            height: 300px;
            margin: 50px auto;
            border: 1px solid #ccc;
            text-align: center;
        }
        .group h3{
            background-color: #eee;
            border-bottom: 1px solid #ccc;
        }
        .hide{
            display: none;
        }
        .show{
            display: block;
        }
    </style>
</head>
<body>
    <div id="contact">
        <div class="group">
            <h3>朋友</h3>
            <div class="ps show">
                <p>a</p>
                <p>b</p>
            </div>
        </div>
        <div class="group">
            <h3>同学</h3>
            <div class="ps hide">
                <p>c</p>
                <p>d</p>
            </div>
        </div>
        <div class="group">
            <h3>亲友</h3>
            <div class="ps hide">
                <p>e</p>
                <p>f</p>
            </div>
        </div>
    </div>

    <script>
        var h3s=document.querySelectorAll('#contact .group h3');
        for(var i=0;i<h3s.length;i++){
            var h3=h3s[i];
            h3.onclick=function(){
                //1.所有组隐藏
                var pers=document.querySelectorAll('#contact .group .ps')
                for(var j=0;j<pers.length;j++){
                    pers[j].className='ps hide';
                }
                //2.显示被单击的组后的div
                this.nextElementSibling.className='ps show';
            }
        }
    </script>
</body>
</html>